<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base],
  components: {
    SelectImageRadio: async () =>
    Vue.extend(
        await Vue.prototype.$vFN.Components.Base.SelectImageRadio()
      ),
    SelectLink: async () =>
      Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectLink()),
  },
  data() {
    return {
      appWindow: window,
      load: false,

      // 页面接口地址
      apiUrl: {
         shareSettings: "mall-site-portal/platform-setting/getShareSettingItem",
         updateShare: "mall-site-portal/platform-setting/updateShareSetting",
      },

      // 分享设置表单
      shareForm: {
        shareType: "",         // 选择分享方式
        mpShareUrl: "",        //公众号分享图路径
        shareImageType: "",   // 分享图片 1页面截图 2自定义图片
        shareImageUrl: "",   // 分享图片
        shareRemark: "",    //分享简介
        shareTitle: "",    //分享标题
        shareUrl: "",     //分享地址
      },

    };
  },
  methods: {
    // 初始化
    async init() {
      this.load = true;
      this.getShareSet();
      this.load = false;
    },

    // 获取分享的数据
    async getShareSet() {
      let res = await this.$vFN.Http.post(
        {
          url: this.apiUrl.shareSettings,
        },
        window
      );
      if (res._ok) {
        for (const key in this.shareForm) {
          if (!this.$vFN.Utils.isEmpty(res.data[key])) {
              // 修改参数类型
              if(key == 'shareImageType' || key == 'shareType'){
                 this.shareForm[key] = res.data[key].toString();
              }else{
                  this.shareForm[key] = res.data[key];
              }

          }
        }

      }
    },

    // 保存事件
    async updateShare() {
     
      let res = await this.$vFN.Http.post(
        {
          url: this.apiUrl.updateShare,
          data: {
            ...this.shareForm,
          },
        },
        window
      );

      if (res._ok) {
        this.$vFN.Tools.messageSuccess(res.message);
        this.init();
      }
    },

  },
  mounted() {
    this.init();
  },

  activated() {},
};
</script>
